package com.biancheng.biancheng.biancheng6;

import java.util.Scanner;

public class 冒泡排序 {

    public static void main(String[] args) {
        int sc;
        System.out.print("输入数组的长度：");
        Scanner s=new Scanner(System.in);
        sc=s.nextInt();
        int[] arr=new int[sc];//定义数组的长度
        for (int n = 0; n <sc; n++) {
            System.out.print("第"+(n+1)+"个数字：");
            Scanner s1=new Scanner(System.in);
            arr[n]=s1.nextInt();
        }

        for (int i = 0; i <arr.length-1; i++) {
            for (int j=0;j<arr.length-i-1;j++) {
                if (arr[j] > arr[j + 1]) {
                    int c;
                    c = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = c;
                }
            }

        }
        System.out.println("数组串升序排列为：");
        int i=0;
        for (int a:arr) {
            if(i != arr.length-1) {
                System.out.print(a + " ");
                i++;
            }else {
                System.out.print(a);
            }
        }
    }


}
